//
//  LSZThreeWillBeLessonViewController.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/8/28.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZThreeWillBeLessonViewController.h"

@interface LSZThreeWillBeLessonViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong) UITableView * tableViewThreeWillBeLesson;
@property(nonatomic,strong) NSMutableArray * mutArrayData;
@property(nonatomic,assign) NSInteger page;
@end

@implementation LSZThreeWillBeLessonViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self getDataThreeWillBeLesson:1];
//    [self.tableViewThreeWillBeLesson reloadData];
}
-(void)getDataThreeWillBeLesson:(NSInteger)page
{
    [LSZRequestDicData threeMeetingsAndOneClassBranchActivities:self.id_id :^(BOOL isOk, NSString * string, LSZPartyBranchActivitiesManager * manager) {
        if (isOk == YES) {
            if (page == 1) {
                [self.mutArrayData removeAllObjects];
                [self.mutArrayData addObjectsFromArray:manager.arrayData];
            }else{
                [self.mutArrayData addObjectsFromArray:manager.arrayData];
            }
            [self.tableViewThreeWillBeLesson reloadData];
        }else{
            if ([string isEqualToString:@"重复登录"]) {
                [LSZPublicClassDataToll RepeatLoginInterfaceJump:self.view fromVC:@"LSZThreeWillBeLessonViewController"];
            }else{
                [LSZPublicClassDataToll initWithAlertKuangView:self.view string:string];
            }
        }
    }];
}
-(void)goToLogin
{
    [LSZPublicClassDataToll goToLogin];
}
-(void)addNotificationCenter
{
    NSString * strDelete = [NSString stringWithFormat:@"%@Login",@"LSZThreeWillBeLessonViewController"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToLogin) name:strDelete object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self addNotificationCenter];
    self.mutArrayData = [[NSMutableArray alloc]init];
    self.page = 1;
    [self getDataThreeWillBeLesson:self.page];
    [self.tableViewThreeWillBeLesson registerClass:[LSZDocumentdetailsCell class] forCellReuseIdentifier:@"LSZDocumentdetailsCell"];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mutArrayData.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.0001;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZDocumentdetailsCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZDocumentdetailsCell" forIndexPath:indexPath];
    if (self.mutArrayData.count > 0) {
        LSZPartyBranchActivitiesMg * mg = nil;
        mg = self.mutArrayData[indexPath.row];
        cell.partyBranchActivitiesMg = mg;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.mutArrayData.count > 0) {
        LSZPartyBranchActivitiesMg * mg = nil;
        mg = self.mutArrayData[indexPath.row];
        LSZDetailsBranchActivitiesVC * vc = [[LSZDetailsBranchActivitiesVC alloc]init];
        vc.branchActivitiesMg = mg;
        [self.navigationController pushViewController:vc animated:YES];
    }
}
-(UITableView *)tableViewThreeWillBeLesson
{
    if(_tableViewThreeWillBeLesson == nil){
        _tableViewThreeWillBeLesson = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,ScreenWidth,ScreenHeight-44-20) style:UITableViewStyleGrouped];
        _tableViewThreeWillBeLesson.delegate = self;
        _tableViewThreeWillBeLesson.dataSource = self;
        _tableViewThreeWillBeLesson.estimatedRowHeight=0;
        _tableViewThreeWillBeLesson.estimatedSectionFooterHeight =0;
        _tableViewThreeWillBeLesson.estimatedSectionHeaderHeight =0;
        [_tableViewThreeWillBeLesson setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        [self.view addSubview:_tableViewThreeWillBeLesson];
    }
    return _tableViewThreeWillBeLesson;
}
@end
